package com.ad.pet.app.account.record;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.account.Point;
import com.ad.pet.models.remote.account.YueDetail;

import javax.inject.Inject;

/**
 * Created by liuyixiang on 2019/10/29.
 */
@PerActivity
public class PointDetailPresenter  extends AbsBasePresenter implements PointDetailContracts.Presenter{
    private ApiService mApiService;
    private PointDetailContracts.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public PointDetailPresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(PointDetailContracts.View view) {
        this.mView = view;
    }


    @Override
    public void getYueDetail(String page) {
        mRxDisposable.add(mApiService.getYueDetail(page)
                .subscribe(new AppSubscriber<YueDetail>(mView) {
                    @Override
                    public void next(YueDetail keyWord) {
                        mView.getYueDetailSuccess(keyWord);
                    }
                }));
    }

    @Override
    public void getPointDetail(final String page) {
        mRxDisposable.add(mApiService.getPointDetail(page)
                .subscribe(new AppSubscriber<Point>(mView) {
                    @Override
                    public void next(Point keyWord) {
                        mView.getPointDetailSuccess(keyWord);
                    }
                }));
    }
}
